home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Alpha ƒ / Tcl / SystemCode / pasteWordUnderMouse.tcl < prev    next >
Text File  |  1995-06-01  |  3KB  |  117 lines

  1. # **************************************************************
  2. #  Filename  :  pasteWordUnderMouse.tcl
  3. #  Author    :   HjK
  4. #  Creation Date:    11.03.1995 {14:06:59 Uhr}
  5. #  Last   update:    24.04.1995 {11:25:53 Uhr}
  6. #  System    :  Alpha Version 6.0b13, Mar. 25, 1995
  7. #  Copyright: Juergen Krey, 11.03.1995
  8. #  MAIL:      Bergstr. 38, 53783 Eitorf
  9. #  E-mail:    krey@gmd.de
  10. # **************************************************************
  11. # Trying to program pasteWordUnderMouse
  12.  
  13. # matchIt doesnt work correct for () and [] at some positions
  14. # therefore use balance, if appropriate
  15. # There are four possible Delimiter matches
  16. # Ñ openingDelim right of mouse-pointed position
  17. # Ñ openingDelim left of mouse-pointed position
  18. # Ñ closingDelim right of mouse-pointed position
  19. # Ñ closingDelim left of mouse-pointed position
  20. # ... they are treated in the enumerated order!
  21.  
  22. proc pasteWordUnderMouse { {insertWhitespace 0} } {
  23.     set res [catch {mousePos} mousePos]
  24.     if {$res != 0} { return }
  25.     set oldCursorPos [getPos]
  26.     set bufferPos [eval rowColToPos $mousePos]
  27.     goto $bufferPos
  28.     
  29.     set nextPos [expr $bufferPos + 1]
  30.     set nextChar [getText $bufferPos $nextPos]
  31.     
  32.     set prevPos [expr $bufferPos - 1]
  33.     set prevChar [getText $prevPos $bufferPos]
  34.     
  35.     set closingDelims "\x29\x5d\x7d"
  36.     set openingDelims "\x28\x5b\x7b"
  37.     
  38. # Ñ openingDelim right of mouse-pointed position
  39.     if {[string first $nextChar $openingDelims] != -1} {
  40.         goto $nextPos
  41.         set balanceFailed [catch {balance}]
  42.         if {! $balanceFailed} {
  43.             set res [getSelect]
  44.             goto $oldCursorPos
  45.             insertText $res
  46.             return
  47.         }    
  48.     }
  49.     
  50. # Ñ openingDelim left of mouse-pointed position
  51.     if {[string first $prevChar $openingDelims] != -1} {
  52.         set balanceFailed [catch {balance}]
  53.         if {! $balanceFailed} {
  54.             set res [getSelect]
  55.             goto $oldCursorPos
  56.             insertText $res
  57.             return
  58.         }    
  59.     }
  60.  
  61. # Ñ closingDelim right of mouse-pointed position
  62.     if {[string first $nextChar $closingDelims] != -1} {
  63.         set balanceFailed [catch {balance}]
  64.         if {! $balanceFailed} {
  65.             set res [getSelect]
  66.             goto $oldCursorPos
  67.             insertText $res
  68.             return
  69.         }    
  70.     }
  71.  
  72. # Ñ closingDelim left of mouse-pointed position
  73.  
  74.     if {[string first $nextChar $closingDelims] != -1} {
  75.         goto $prevPos
  76.         set balanceFailed [catch {balance}]
  77.         if {! $balanceFailed} {
  78.             set res [getSelect]
  79.             goto $oldCursorPos
  80.             insertText $res
  81.             return
  82.         }    
  83.     }
  84. # Ñ normal insertion of a wordBreak-Pattern string
  85.  
  86.     backwardWord
  87.     set from [getPos]
  88.     forwardWord
  89.     set to [getPos]
  90.     set res [getText $from $to]
  91.     goto $oldCursorPos
  92.     switch $insertWhitespace {
  93.         0 {set res " $res "}
  94.         1 {}
  95.         2 {append res .}
  96.         default {}
  97.     }
  98.     insertText $res
  99. }
  100. #endproc pasteWordUnderMouse
  101.  
  102. ##############################################################################
  103.  
  104. bind F10 <s>    {pasteWordUnderMouse 0}
  105. bind F10          {pasteWordUnderMouse 1}
  106. bind F10 <z>     {pasteWordUnderMouse 2}
  107.  
  108.  
  109.  
  110. # **************************************************EOF